package xulong.com.weiyulinked.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;
@Component
@EnableWebSocket
public class WebSocketRegister implements WebSocketConfigurer {
    @Autowired
    private  WebSocketConfig webSocketConfig;
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        //添加websocket的handler
       registry.addHandler(webSocketConfig,"/sentMessage")
                //添加拦截器,用于获取session中的用户信息
                .addInterceptors(new HttpSessionHandshakeInterceptor())
                //设置允许跨域
                .setAllowedOrigins("*");


    }
}
